perm filename GETTIM.MAC[11,HE] blob
sn#744182 filedate 1984-02-25 generic text, type C, neo UTF8
COMMENT ā VALID 00002 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 Program to get the time-of-day from the ethernet & set the system time to it
C00007 ENDMK
Cā;
;Program to get the time-of-day from the ethernet & set the system time to it
.TITLE GETTIM
.DSABL GBL
.MCALL QIOW$S,QIO$S,ALUN$S,RDAF$S,WTLO$S,MRKT$S,CMKT$S,EXIT$S,SPWN$S
.GLOBL IO.WLB
.GLOBL IO.RLB
.GLOBL IO.KIL
ENOUT = 1 ;Ethernet output channel
ENIN = 2 ;Ethernet input channel
TTY = 3 ;TTY input/output channel
PUP = 1000 ;Pup packet identifier
PUPOV = 22.
PUPSIZ = 560.
TIMREQ = 200 ;Time request pup type
TIMREP = 201 ;Time reply pup type
OUTPUP: .BYTE 304,0
.WORD PUP,PUPOV,TIMREQ,0,1
.BYTE 0,50
.WORD 0,4
SRCHST: .BYTE 304,50
.WORD 0,104,0
INPUP: .BLKW 2
SIZE: .WORD 0
RTYPE: .BLKW 7
TIME: .BLKW 2
DATE: .BLKW PUPSIZ
IOSB: .BLKW 2
FLAGS: .BLKW 4
MCR: .RAD50 /MCR.../
PROMPT: .ASCII <15><12>/PLEASE ENTER TIME AND DATE (HR:MN DD-MMM-YY) /
PRSIZE = .-PROMPT
.EVEN
START: ALUN$S #ENOUT,#"EN,#0 ;Assign LUN for output
ALUN$S #ENIN,#"EN,#1 ;Assign LUN for input
ALUN$S #TTY,#"TI,#0 ;Assign LUN for TTY
QIO$S #3000,#ENIN,,,#IOSB
MOVB IOSB+2,OUTPUP ;Put our host number in time request
MOVB IOSB+2,SRCHST
MOV #OUTPUP+4,R1 ;Now compute checksum
MOV #10.,R2
CLR R0
1$: ADD (R1)+,R0 ;One's complement addition
ADC R0
ASL R0 ;Rotate left
ADC R0
SOB R2,1$
CMP R0,#177777 ;Change negative zero checksum to positive zero
BNE 2$
CLR R0
2$: MOV R0,(R1) ;Store away checksum
MOV #10.,R3 ;Number of times that we'll try
;Get ready to receive the reply packet
TRY: QIO$S #IO.RLB,#ENIN,#1,,,,<#INPUP,#PUPSIZ,#104,#0,#0,#0>
3$: QIO$S #IO.WLB,#ENOUT,,,,,<#OUTPUP,#PUPOV+4> ;Send out the packet
MRKT$S #2,#1,#2 ;Time out in one second
WTLO$S 0,#3 ;Wait for pup or time-out
RDAF$S #FLAGS ;See what happened
BIT #1,FLAGS ;Pup received
BNE 5$ ; Yes
SOB R3,3$ ; No - try sending it out again
BR NOGOOD ;No luck after 10 tries - give up
4$: BR TRY
5$: CMKT$S
CMPB #TIMREP,RTYPE ;Is it a time reply pup?
BEQ GOOD ; Yes - use it to set system time
SOB R3,4$ ; No - try it again
BR NOGOOD ;No luck after 10 tries - give up
GOOD: MOV SIZE,R0 ;R0 = pup length in bytes (including overhead)
SUB #22.,R0 ;R0 = pup length in bytes of data
BEQ TRY ;Try again if empty packet
MOV R0,R2
INC R0 ;Make it a word count
ASR R0
MOV #DATE,R1 ;R1 = LOC(start of data)
1$: SWAB (R1)+ ;Swap the two data bytes in this word
SOB R0,1$ ;Do them all
SETTIM: ADD #4,R2 ;Length of date string
MOV #"TI,TIME ;Preface date string with "TIM "
MOV #"M ,TIME+2
SPWN$S #MCR,,,,,#1,,,#TIME,R2 ;Spawn the time request
FIN: QIO$S #IO.KIL,#ENIN ;Flush any pending pup reads
EXIT$S ;All done
;
;Ethernet let us down - ask user for time
;
NOGOOD: QIOW$S #IO.WLB,#TTY,#1,,,,<#PROMPT,#PRSIZE,#0> ;Type out prompt
QIOW$S #IO.RLB,#TTY,#1,,#IOSB,,<#DATE,#80.> ;Read in a line
MOV IOSB+2,R2 ;Length of line read in
BR SETTIM
.END START